using FarseerGames.FarseerPhysics;
using FarseerGames.FarseerPhysics.Factories;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using XNA_2DFramwork;

namespace ArtificialIntelligence.Racing
{
    public class City:VisualObject
    {
        Texture2D VisualTexture1;
        Texture2D VisualTexture2;
        Texture2D FinishTexture;
        Vector2 pos1 = new Vector2(0, -1000);
        Vector2 pos2 = new Vector2(0, 0);
        public static float RacerLenght;
        public static float CurrentLenght;
        public City(Game game, string filename, string finishTextureName, PhysicsSimulator PhysicsSimulator)
            : base(game)
        {
            RacerLenght = 100000;
            
            VisualTexture1 = game.Content.Load<Texture2D>(filename);
            VisualTexture2 = game.Content.Load<Texture2D>(filename);
            Width = VisualTexture1.Width;
            Height = VisualTexture1.Height;
            FinishTexture = game.Content.Load<Texture2D>(finishTextureName);
            Position = pos1;
            Body = BodyFactory.Instance.CreateRectangleBody(PhysicsSimulator, Width, Height, 1);
            Body.Position = pos1;
            Geom = GeomFactory.Instance.CreateRectangleGeom(PhysicsSimulator, Body, Width, Height);
            Body.IgnoreGravity = true;
            Geom.CollisionResponseEnabled = false;
            SpriteBatch = new SpriteBatch(Game.GraphicsDevice);

        }
        public override void Draw()
        {
            this.SpriteBatch.Begin();
            this.SpriteBatch.Draw(VisualTexture2, pos2, Color.White);
            this.SpriteBatch.Draw(VisualTexture2, pos1, Color.White);
            if (CurrentLenght >= RacerLenght)
                SpriteBatch.Draw(FinishTexture, new Vector2(250, 500), Color.White);
            this.SpriteBatch.End();
        }
        public void Move(float x, float y)
        {
            if (CurrentLenght < RacerLenght)
            {
                CurrentLenght += RacePlayer.playerS;
                pos1.Y += y;
                pos2.Y += y;
                if (y > 0)
                {
                    if (pos1.Y >= 1000)
                    {
                        pos1.Y = -1000;
                        pos2.Y = pos1.Y + VisualTexture2.Height;
                    }
                    if (pos2.Y >= 1000)
                    {
                        pos2.Y = -1000;
                        pos1.Y = pos2.Y + VisualTexture1.Height;
                    }
                }
                if (y < 0)
                {
                    if (pos1.Y <= -1000)
                    {
                        pos1.Y = 1000;
                        pos2.Y = pos1.Y - VisualTexture2.Height;
                    }
                    if (pos2.Y <= -1000)
                    {
                        pos2.Y = 1000;
                        pos1.Y = pos2.Y - VisualTexture1.Height;
                    }
                }
            }
        }
        public override void Update()
        {
        }
    }
}
